//品名,颜色,网目,宽度不同的不可以一起生成生产计划
define([],function(){
    return {
        data: function() {
          return {
            barcode:'',
            row:[],
            btnHandel:false,
            loading:true
          }
        },
        components:{
          // 'comp-procedure-progress':resolve=>require(['_vue!pathComponent/comp-procedure-progress'], resolve),
        },
        methods:{
            searchBarCode(){
                if(this.btnHandel){
                    return;
                }

                this.btnHandel = true;
                // dump(this.barcode);
                let that = this;
                this.$http.post('?controller=Sample_Cart&action=GetSampleInfo',{barcode:this.barcode}).then((res)=>{
                    if(res.data.msg) {
                        this.$notify.error({
                            'title':'提示',
                            'message':res.data.msg
                        });
                    }

                    if(res.data.success){
                        // 添加到样品列表中，判断是否重复
                        let _index = that.row.findIndex((item, index, arr) => item.code == res.data.sample.code);
                        // dump({_index});
                        if(_index < 0){
                            that.row.splice(that.row.length,0,res.data.sample);
                        }else{
                            this.$notify.error({
                                'title':'提示',
                                'message':"已添加："+res.data.sample.code
                            });
                        }

                        this.barcode = '';
                    }

                    this.btnHandel = false;
                }).catch(function (error) {
                    that.$notify.error({
                        'title':'请求失败',
                        'message':'请求失败,检查url或者其他设置'
                    });
                    this.btnHandel = false;
                });
            },
            printAll(){
                if(this.row.length == 0){
                    this.$notify.error({
                        'title':'提示',
                        'message':"请先添加样品信息"
                    });
                    return;
                }
                let rukuId = this.row.map((item) => item.rukuId);
                rukuId = rukuId.join(',');

                let url = '?controller=Sample_Ruku&action=print&id='+rukuId;
                if(window.top.openNewTap){
                    window.top.openNewTap(url,'样品报价');
                }else{
                    window.location.href = url;
                }

            },
            removeRow(index){
                // dump({index})
                this.row.splice(index,1);
            },
            exportExcel(){
                if(this.row.length == 0){
                    this.$notify.error({
                        'title':'提示',
                        'message':"请先添加样品信息"
                    });
                    return;
                }
                let rukuId = this.row.map((item) => item.rukuId);
                rukuId = rukuId.join(',');
                window.location.href = '?controller=Sample_Cart&action=Export&id='+rukuId;
            },
            baojia(){
                if(this.row.length == 0){
                    this.$notify.error({
                        'title':'提示',
                        'message':"请先添加样品信息"
                    });
                    return;
                }
                let rukuId = this.row.map((item) => item.rukuId);
                rukuId = rukuId.join(',');
                let url = '?controller=Baojia_Quotation&action=Add&from=sample&sampleId='+rukuId;
                if(window.top.openNewTap){
                    window.top.openNewTap(url,'样品报价');
                }else{
                    window.location.href = url;
                }
            },
        },
        mounted : function() {

        }
    }
})